package Servlet;

import javaBean.Message;
import useBean.MessageDB;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>Title: QueryMessageServlet</p>
 * <p>author 12427</p>
 *
 * @version ver1.0
 * @date 2021/12/21 23:34
 */

@WebServlet("/QueryMessageServlet")
public class QueryMessageServlet extends HttpServlet {

    /**
     * @see HttpServlet doGet(HttpServletRequest, HttpServletResponse) (HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        String url ="/query.jsp";
        List<Message> mL= null ;
        try {
            mL = QueryMessage(request,response);
            request.setAttribute("MessageListByUname" , mL);
        } catch (Exception e) {
            e.printStackTrace();
        }
        request.getServletContext().getRequestDispatcher(url).forward(request, response);
    }

    private List<Message> QueryMessage(HttpServletRequest request,HttpServletResponse response) throws Exception {
        return MessageDB.selectMessageByUname((String) request.getParameter("user_name")) ;
    }
}
